package com.situ.stmall.manager.entity;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * 服务器想客户端返回的JSON数据
 */
@Data //相当于@Getter和@Setter
@ToString
@NoArgsConstructor
public class Result {
    /**
     * 操作的状态码
     */
    private  Integer code;
    /**
     * 返回错误的信息
     */
    private String msg;
    /**
     * 查询结果
     */
    private Object data;

    //静态方法
    public static Result success(Integer code, String msg, Object data){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);

        return result;
    }
    public static Result success(Object data){
        return  success(0,null,data);
    }
    public static Result success(){
        return  success(0,null,null);
    }

    //失败
    public static Result error(Integer code, String msg, Object data){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);

        return result;
    }
    public static Result error(Integer code, String msg){
        return  error(code, msg, null);
    }
    public static Result error(String msg){
        return  error(-1,msg,null);
    }
}
